package org.sharing.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SearchAction extends ActionSupport {

	String name;
	String author;
	String type;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	String target;

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String execute() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		ctx.getSession().remove("name");
		ctx.getSession().remove("author");
		if (!getAuthor().trim().equals("")) {
			setAuthor("%" + getAuthor() + "%");
			ctx.getSession().put("author", getAuthor());
		}
		if (!getName().trim().equals("")) {
			setName("%" + getName() + "%");
			ctx.getSession().put("name", getName());
		}
		 System.out.println(getName() + "  " + getAuthor() + "  " +
		 getType());
		setTarget("result.jsp?id=" + getType());
		return SUCCESS;
	}
}
